#coding=utf-8
import json
import sys
import os
import shutil
from os.path import walk, join, normpath 
import codecs

def removeBom(file):
	f1 = open(file,"r")
	s1 = f1.read()
	hasBom = False
	if s1.startswith(codecs.BOM_UTF8):
		s1 = s1[len(codecs.BOM_UTF8):]
		hasBom = True
	f1.close()
	if hasBom:
		f2 = open(file,'w')
		f2.write(s1)
		f2.close()
	return hasBom
def removeBomPath(dir):
	for root, dirs, files in os.walk(dir):
		for file in files:
			if os.path.isfile(os.path.join(root,file)):
				if removeBom(os.path.join(root,file)):
					print "转换为无bom格式文件========".decode('utf-8').encode('gbk'),file
				else:
					print "已经是无bom格式文件========".decode('utf-8').encode('gbk'),file
				
#入口
if __name__=="__main__":
	print "=========================开始转换bom格式为无bom格式============================".decode('utf-8').encode('gbk')
	removeBomPath("./src")
	print "=========================转换完成============================".decode('utf-8').encode('gbk')